<?php
    $entity = pc_variable("entity");
    $attribute = pc_variable("attribute");
    $name = pc_variable("name");
    $value = pc_variable("value");
    $errors = pc_variable("errors");
    if($errors !== null && $errors->get($name) !== null) {
        $value = pc_variable("entity." . $name);
    } else if($value !== null) {
        $ids = new Pageley_Util_ArrayMap();
        foreach($value as $reference) {
            $ids->add($reference->getId());
        }
        $value = $ids;
    }
?>
<label<?php if($attribute->isRequired()) { ?> class="required"<?php } ?>><?php pc_echo(pc_message("field." . $name)); ?></label>
<ul class="multiple">
    <?php
        if($entity !== null && $entity->getType() == $attribute->getType()) {
            pc_pagelet(
                "show-entity/attribute/multiple-list",
                array(
                    "name" => $name,
                    "typeName" => $attribute->getType()->getFullName(),
                    "propertyNames" => array("id"),
                    "operators" => array("!="),
                    "values" => array($entity->getId()),
                    "ids" => $value),
                "Query");
        } else {
            pc_pagelet(
                "show-entity/attribute/multiple-list",
                array(
                    "name" => $name,
                    "typeName" => $attribute->getType()->getFullName(),
                    "ids" => $value),
                "Query");
        }
    ?>
</ul>
<br/>